package com.snopy.service.impl;

import com.snopy.mapper.StuMapper;
import com.snopy.pojo.Stu;
import com.snopy.service.StuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * TODO
 *
 * @author snoopy
 * @date 2020/9/19 0019 11:04
 * @email 77912204@qq.com
 * @remark
 */
@Service
public class StuServiceImpl implements StuService {

    @Resource
    private StuMapper stuMapper;


    @Transactional(propagation = Propagation.SUPPORTS)
    @Override
    public Stu getStuInfo(int id) {
        return stuMapper.selectByPrimaryKey(id);
    }


    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void saveStu() {
        Stu stu = new Stu();
        stu.setName("小鱼儿");
        stu.setAge(13);
        stu.setId(12);
        stuMapper.insert(stu);
    }


    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void modifyStu(int id) {
        Stu stu = new Stu();
        stu.setName("花木兰");
        stu.setAge(13);
        stu.setId(12);
        stuMapper.updateByPrimaryKey(stu);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    @Override
    public void deleteStu(int id) {
        stuMapper.deleteByPrimaryKey(id);
    }
}
